<template>
  <el-drawer
    :title="title"
    :visible.sync="isVisible"
    :size="size"
    :append-to-body="appendToBody"
    :custom-class="customClass"
    :close-on-press-escape="closeOnPressEscape"
    :destroy-on-close="destroyOnClose"
    :modal="modal"
    :modal-append-to-body="modalAppendToBody"
    :show-close="showClose"
    :wrapper-closable="wrapperClosable"
    @open="open"
    @opened="opened"
    @close="close"
    @closed="closed"
  >
    <div class="wf-drawer-cont">
      <slot />
    </div>
    <div class="wf-drawer-foot">
      <slot name="footer">
        <div>
          <el-button @click="cancel">取消</el-button>
          <el-button type="primary" @click="ok">确认</el-button>
        </div>
      </slot>
    </div>
  </el-drawer>
</template>

<script>
  // 只支持从右侧划出，不支持隐藏header和footer
  export default {
    name: 'WfElDrawer',
    props: {
      title: {
        type: String,
        default: '',
      },
      size: {
        type: String,
        default: '560px',
      },
      visible: {
        type: Boolean,
        default: false,
      },
      appendToBody: {
        type: Boolean,
        default: false,
      },
      customClass: {
        type: String,
        default: '',
      },
      closeOnPressEscape: {
        type: Boolean,
        default: true,
      },
      destroyOnClose: {
        type: Boolean,
        default: false,
      },
      modal: {
        type: Boolean,
        default: true,
      },
      modalAppendToBody: {
        type: Boolean,
        default: true,
      },
      showClose: {
        type: Boolean,
        default: true,
      },
      wrapperClosable: {
        type: Boolean,
        default: true,
      },
    },
    data() {
      return {
        isVisible: false,
      };
    },
    watch: {
      visible(value) {
        this.isVisible = value;
      },
    },
    methods: {
      cancel() {
        this.$emit('on-cancel');
        this.isVisible = false;
      },
      ok() {
        this.$emit('on-ok');
        this.isVisible = true;
      },
      open() {
        this.$emit('open');
      },
      opened() {
        this.$emit('opend');
      },
      close() {
        this.$emit('close');
      },
      closed() {
        this.$emit('closed');
        this.$emit('update:visible', false);
      },
    },
  };
</script>

<style lang="scss" scoped>
  .wf-drawer-cont {
    height: calc(100vh - 143px);
    overflow-x: hidden;
    overflow-y: auto;
    padding: 15px 20px 5px 20px;
  }
  .wf-drawer-box-label {
    margin-bottom: 20px;
    font-weight: bold;
  }
  .wf-drawer-foot {
    border-top: 1px solid #f7f6f9;
    text-align: right;
    padding: 0 25px;
    height: 73px;
    line-height: 73px;
  }
</style>
